import vue from '@vitejs/plugin-vue'

import path, { resolve } from 'path'

import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  // ...
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver(),],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  //解决“vite use `--host` to expose”
  base: './',
  server: {
    proxy: {
      '/api': { // 获取请求中带 api 的请求
        target: 'http://localhost:8080', // 后台服务器源
        changeOrigin: true, // 修改源
        rewrite: (path) => path.replace(/^\/api/, "") //  /api 替换为空字符串
      }
    }
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.vue'],
    //别名配置，引用src路径下的东西可以通过@如：import Layout from '@/layout/index.vue'
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src')
      }
    ]
  }
})